<?php
namespace app\api\model;

/**
 * Created by PhpStorm.
 * User: muyu
 * Date: 2018/1/25
 * Time: 20:31
 */
class Theme extends   BaseModel{
//    hasone  和 belongsto 都是一对一关系，theme 包含img 所以用belongsto
protected $hidden = ['update_time','delete_time'];
    public function topImg(){
        return $this->belongsTo('Image','topic_img_id','id');
    }
    public function headImg(){
        return $this->belongsTo('Image','head_img_id','id');
    }
    public function products(){
        return $this->belongsToMany('Product','theme_product','product_id','theme_id');//多对多
    }

    public static function getTheme($ids)
    {
        $result = self::with('topImg','Image')->select($ids);
       return  $result;
    }
    public static function getCmp($id){
        return   self::with('products','topImg','headImg')->find($id);//多对多关联
    }

}